<template>
  <div class="scrolling-list-container">
    <div class="list-wrapper" style="padding: 10px">
      <div id="echart-line-chart" style="width: 100%; height: 100%"></div>
    </div>
  </div>
</template>

<script>
import Velocity from "velocity-animate";
import { listSimCard } from "@/api/maintenance/simCard";
import vueSeamlessScroll from "vue-seamless-scroll";
import request from "@/utils/request";
import * as echarts from "echarts";

export default {
  name: "SimCard",
  components: {
    vueSeamlessScroll,
  },
  data() {
    return {
      chart: null,
    };
  },
  mounted() {
    request({
      url: "/zk/substation/region-pie",
      method: "get",
    }).then((res) => {
      console.log("result", res);
      this.initChart(res.data);
    });
  },
  methods: {
    initChart(pieData) {
      this.chart = echarts.init(document.getElementById("echart-line-chart"));
      const option = {
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b}: {c} ({d}%)'
        },
        // legend: {
        //   orient: 'vertical',
        //   left: 'left'
        // },
        series: [
          {
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: false,
            padAngle: 5,
            label: {
              show: true,
              formatter: '{b}',
              textBorderColor: 'transparent',
              textBorderWidth: 0,
              color: '#fff'
            },
            data: pieData,
            itemStyle: {
              borderRadius: 3
            },
            emphasis: {
              itemStyle: {
                shadowBlur: 10,
                shadowOffsetX: 0,
                shadowColor: 'rgba(0, 0, 0, 0)'
              }
            }
          }
        ]
        ,
      };
      this.chart.setOption(option);
      window.addEventListener("resize", this.handleResize);
    },
    handleResize() {
      if (this.chart) {
        this.chart.resize();
      }
    },
  },
  beforeDestroy() {
    if (this.chart) {
      window.removeEventListener("resize", this.handleResize);
      this.chart.dispose();
    }
  },
};
</script>

<style lang="scss" scoped>
.list-wrapper {
  height: 243px;
  width: 100%;
  margin: 0 auto;
  overflow: hidden;

  ul {
    list-style: none;
    padding: 0;

    li,
    a {
      display: block;
      display: flex;
      justify-content: space-between;
      font-size: 15px;
    }
  }
}

/* You can write your component-specific styles here */
</style>
